package cn.jy.boot.controller;

import cn.jy.boot.pojo.User;
import cn.jy.boot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @ResponseBody
    @RequestMapping("/user/{id}")
    public String getUser(@PathVariable("id") Integer id){
        User user = userService.getUserById(null,id);
        if (user==null){
            return "null";
        }
        return user.toString();
    }

    @ResponseBody
    @RequestMapping("/user/up/{id}")
    public String updateUser(@PathVariable("id") Integer id){
        User user = userService.getUserById(null,id);
        user.setUserName("zs");
        userService.updateUserById(user);
        return user.toString();
    }

    @ResponseBody
    @RequestMapping("/user/del/{id}")
    public String delUser(@PathVariable("id") Integer id){
        userService.delUser(id);
        return null;
    }


}
